<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
require_once BASE_PATH . 'application/controllers/base' . EXT;

class Canal extends Base {

    public function __construct() {
        parent::__construct();
        $this->load->model('itemDAO');
        $this->load->model('moduleDAO');
        $this->load->model('paginationDAO');
        $this->load->model('categoryDAO');
        $this->load->model('adsDAO');
        $this->load->model("sessionDAO");
        $this->load->model("suscriptoresDAO");
    }

    public function index($id = 1) {

        $categoria = $this->categoryDAO->findById($id);

        if (count($categoria) == 0)
            redirect('/');

        $this->itemDAO->setHit($id);

        /* Items con Paginaci�n */
        $articulos = $this->itemDAO->findItemsByCategoriesId($id, array("order" => array("publish_up", "DESC")));
        $paginacion = $this->paginationDAO->getItems(array("paginas" => 5, "total" => count($articulos), "url" => "./canal/" . $id));

        $articulos = $this->itemDAO->findItemsByCategoriesId($id, array('limit' => array($paginacion["inicio"], $paginacion["fin"]), "order" => array("publish_up", "DESC")));

        $lomasleido = $this->itemDAO->findItemsByCategoriesId($id, array("where" => "created >= DATE_ADD(NOW(),INTERVAL -15 DAY)", "limit" => array(0, 15), "order" => array("hits", "DESC")));

        $estasemana = $this->moduleDAO->getParamsByStringId("home_estasemana");

        /*
          Publicidad
         */
        $publicidadheader2 = $this->adsDAO->getAdsense("canal_publicidadheaderright");
        $publicidadheader1 = $this->adsDAO->getAdsense("canal_publicidadheaderleft");
        
        $publicidadboxbanner1 = $this->adsDAO->getAdsense("canal_publicidadboxbanner1");
        $publicidadboxbanner2 = $this->adsDAO->getAdsense("canal_publicidadboxbanner2");

        $publicidadmiddlebanner1 = $this->adsDAO->getAdsense("canal_publicidadmiddlebanner1");
        $publicidadmiddlebanner2 = $this->adsDAO->getAdsense("canal_publicidadmiddlebanner2");
                                                              
        //$publicidadboxskyscraper1 = $this->adsDAO->getAdsense("canal_publicidadboxskyscraper1");
        //$publicidadboxskyscraper2 = $this->adsDAO->getAdsense("canal_publicidadboxskyscraper2");
        $publicidadfooterleft = $this->adsDAO->getAdsense("canal_publicidadfooterleft");
        $publicidadfooterright = $this->adsDAO->getAdsense("canal_publicidadfooterright");

        $correopass = $this->input->get('item');
        $data = array(
            "header" => array(
                "title" => "Canal",
                "subtitle" => "",
                "description" => "",
                "correopass" => $correopass,
                "keywords" => "",
                "session" => $this->sessionDAO->getUser(),
                "publicidadheader2" => $publicidadheader2,
                "publicidadheader1" => $publicidadheader1,
            ),
            // Modulos
            "id" => $id,
            "categoria" => $categoria,
            "articulos" => $articulos,
            "paginacion" => $paginacion["paginacion"],
            "estasemana" => $estasemana,
            "lomasleido" => $lomasleido,
            // Publicidad
            "publicidadboxbanner1" => $publicidadboxbanner1,
            "publicidadboxbanner2" => $publicidadboxbanner2,
            //"publicidadboxskyscraper1" => $publicidadboxskyscraper1,
            //"publicidadboxskyscraper2" => $publicidadboxskyscraper2,
            "publicidadmiddlebanner1" => $publicidadmiddlebanner1,
            "publicidadmiddlebanner2" => $publicidadmiddlebanner2,

            "publicidadfooterleft" => $publicidadfooterleft,
            "publicidadfooterright" => $publicidadfooterright,
        );

        $this->load->view('canal/canal', $data);
    }

}